﻿@{
    ViewBag.Title = "查询服务元数据";
}
@using YmtRpc.Domain;
@model List<ServiceMetadata>


<form role="form">
    <div class="form-group">

        <label for="name">服务名称：</label>
        <select class="form-control" style="width:200px" id="appid" name="appid">
            <option value="">全部</option>
            @foreach (string app in ViewBag.AppList)
            {
                if (string.Equals(app, ViewBag.AppId))
                {
                    <option value="@app" selected="selected">@app</option>
                }
                else
                {
                    <option value="@app">@app</option>
                }
            }
        </select>

        <button type="button" class="btn btn-default" onclick="query(); return false;" style="margin-left:10px">查询</button>
    </div>
</form>

<table id="ServiceMetadataTab" class="table table-striped table-bordered table-hover">
    <thead>
        <tr>
            <th style="width:50px">序号</th>
            <th>应用编号</th>
            <th>接口名称</th>
            <th>域名</th>
            <th>接口地址</th>
            <th>http方法</th>
            <th>数据创建时间</th>
            <th>最后一次更新时间</th>
            <th>接口的用途描述</th>
            <th>接口的拥有者</th>
            <th>更新</th>
            <th>删除</th>
        </tr>
    </thead>
    <tbody>
        @if (Model != null)
        {
            int i = 1;
            foreach (ServiceMetadata entity in Model)
            {
                <tr>
                    <td>@(i++)</td>
                    <td>@entity.AppId</td>
                    <td>@entity.ApiName</td>
                    <td>@entity.Host</td>
                    <td>@entity.ApiPath</td>

                    <td>@entity.HttpMethod</td>
                    <td>@entity.CreateTime</td>
                    <td>@entity.LastUpdateTime</td>

                    <td>@entity.Description</td>
                    <td>@entity.Owner</td>
                    <td><a target="_blank" href="/ServiceMetadata/Edit?appId=@entity.AppId&apiName=@entity.ApiName&httpMethod=@entity.HttpMethod">更新</a></td>
                    <td><a href="#" onclick="Delete(this,'@entity.AppId', '@entity.ApiName', '@entity.HttpMethod')">删除</a></td>
                </tr>
            }
        }
    </tbody>
</table>

<script type="text/javascript">
    function query() {
        
        var href = "/ServiceMetadata/Index";
        var app = $("#appid")[0].value;

        if (app != "") {
            href = href + "?appId=" + app;
        }

        location.href = href;
        return false;
    }

    function Delete(obj, appId, apiName, httpMethod) {

        
        var r=confirm("确认删除？");
        if (r==true)
        {
            $.ajax({
                type: "GET",
                url: "/ServiceMetadata/Delete?appId=" + appId+"&apiName=" + apiName+"&httpMethod=" + httpMethod,
                success: function (data) {

                    if(data == true)
                    {
                        $(obj).parent().parent().remove();
                    }
                    else
                    {
                        alert("删除失败");
                    }
                }
            });
        }
    }

</script>



